priority 100

snippet val "overleaf" b
%%begin novalidate
$0
%%end novalidate
endsnippet
snippet macro "\documentclass{ltxdoc}" b
%    \begin{macro}
$0
%    \end{macro}
endsnippet

snippet up "myUltiSnips" b
\usepackage$1{$2}
endsnippet
snippet sec "myUltiSnips" b
\section{${1:section name}}%
\label{sec:${2:$1}}
endsnippet
snippet sec* "myUltiSnips" b
\section*{${1:section name}}%
\label{sec:${2:$1}}
endsnippet
snippet sub "myUltiSnips" b
\subsection{${1:subsection name}}%
\label{sub:${2:$1}}
endsnippet
snippet sub* "myUltiSnips" b
\subsection*{${1:subsection name}}%
\label{sub:${2:$1}}
endsnippet
snippet ssub "myUltiSnips" b
\subsubsection{${1:subsubsection name}}%
\label{ssub:${2:$1}}
endsnippet
snippet ssub* "myUltiSnips" b
\subsubsection*{${1:subsubsection name}}%
\label{ssub:${2:$1}}
endsnippet
snippet par "myUltiSnips" b
\paragraph{${1:paragraph name}}%
\label{par:${2:$1}}
endsnippet
snippet subp "myUltiSnips" b
\subparagraph{${1:subparagraph name}}%
\label{subp:${2:$1}}
endsnippet
snippet ft "myUltiSnips" i
\footnote{$1}$0
endsnippet
snippet index "myUltiSnips" i
\index{$1}$0
endsnippet

snippet tab "\usepackage{booktabs}" b
\begin{tabular}{$1}
	\toprule
	$0\\\\
	\midrule
	\\\\
	\bottomrule
\end{tabular}
endsnippet
snippet mulc
\multicolumn{${1:2}}{c}{${VISUAL}$2}
endsnippet
snippet mulr "\usepackage{multirow}"
\multirow{${1:2}}{*}{${VISUAL}$2}
endsnippet
snippet long "\usepackage{longtable, booktabs}" b
\begin{longtable}{$1}
	\caption{$2}%
	\label{tab:$3}\\\\
	\toprule
	$4\\\\
	\midrule
	\endfirsthead
	\caption{$2 (continued)}\\\\
	\toprule
	$4\\\\
	\midrule
	\endhead
	\\\\
	\midrule
	\endfoot
	\\\\
	\bottomrule
	\endlastfoot
	$0
\end{longtable}
endsnippet

snippet fig "\usepackage{graphicx}" b
\begin{figure}
	\centering
	\includegraphics[
		width=${1:0.8}\linewidth,
	]{images/$2.png}
	\caption{$3}%
	\label{fig:$2}
\end{figure}
endsnippet
snippet stand "\usepackage{standalone}" b
\begin{figure}
	\centering
	\includestandalone{figures/$1}
	\caption{$2}%
	\label{fig:$1}
\end{figure}
endsnippet
snippet csv "\usepackage{csvsimple, booktab}" b
\begin{table}
	\centering
	\caption{$1}%
	\label{tab:$2}
	\csvautobooktabular[respect percent]{tables/$2.csv}
\end{table}
endsnippet
snippet vplayer "\usepackage[playbutton=fancy, passcontext, transparent]{media9, graphicx, shellesc}" b
\begin{figure}
	\centering
	\includemedia[
		width=${1:0.8}\linewidth,
		addresource=media/$2.mp4,
		flashvars={%
			source=media/$2.mp4
		},
	]{%
		\IfFileExists{./media/$2.png}{}{%
			\ShellEscape{ffmpeg -i media/$2.mp4 -t 1 -frames:v 1 media/$2.png}
		}
		\includegraphics[
			width=0.8\linewidth,
		]{media/$2.png}
	}{VPlayer.swf}
	\caption{$3}%
	\label{fig:$2}
\end{figure}
endsnippet
# okular cannot support APlayer.swf
snippet aplayer "\usepackage[playbutton=fancy, passcontext, transparent]{media9, fontawesome5}" b
\begin{figure}
	\centering
	\includemedia[
		addresource=media/$1.mp3,
		flashvars={%
			source=media/$1.mp3
		},
	]{%
		\faIcon{volume-up}
	}{APlayer9.swf}
	\caption{$2}%
	\label{fig:$1}
\end{figure}
endsnippet
snippet animate "\usepackage[autoplay, loop]{animate, graphicx, shellesc}" b
\begin{figure}
	\centering
	\IfFileExists{./media/$1.pdf}{}{%
		\ShellEscape{convert media/$1.gif -coalesce media/$1.pdf}
	}
	\animategraphics[
		width=${2:0.8}\linewidth,
	]{${3:24}}{media/$1}{}{}
	\caption{$4}%
	\label{fig:$1}
\end{figure}
endsnippet
snippet subf "\usepackage{subcaption, graphicx}" b
\begin{subfigure}{${1:0.45}\linewidth}
	\centering
	\includegraphics[
		width=\linewidth,
	]{images/$2.png}
	\caption{$3}%
	\label{fig:$2}
\end{subfigure}
${0:\quad}
endsnippet
snippet subt "\usepackage{subcaption, csvsimple, booktabs}" b
\begin{subtable}{0.45\linewidth}
	\centering
	\caption{$1}%
	\label{tab:$2}
	\csvautobooktabular[respect percent]{tables/$2.csv}
\end{subtable}
${0:\quad}
endsnippet
snippet wrapf "\usepackage{wrapfig}" b
\begin{wrapfigure}{${1:r}}{${2:0.2}\linewidth}
	\centering
	\includegraphics[
		width=\linewidth,
	]{images/$1.png}
	\caption{$2}%
	\label{fig:$1}
\end{wrapfigure}
endsnippet
snippet wrapt "\usepackage{wrapfig}" b
\begin{wraptable}{${1:r}}{${2:0.2}\linewidth}
	\centering
	$0
	\caption{$2}%
	\label{tab:$1}
\end{wraptable}
endsnippet
snippet overpic "\usepackage{overpic}" b
\begin{overpic}[
	width=\linewidth,
	grid,
]{images/$1.png}
	\put($0)
\end{overpic}
endsnippet
snippet Overpic "\usepackage{overpic}" b
\begin{Overpic}[
	width=\linewidth,
	grid,
]{$1}
	\put($0)
\end{Overpic}
endsnippet
snippet tikz "\documentclass[tikz]{standalone}" b
\begin{tikzpicture}$1
	$0
\end{tikzpicture}
endsnippet
snippet scope "\documentclass[tikz]{standalone}" b
\begin{scope}$1
	$0
\end{scope}
endsnippet
snippet alg "\usepackage[linesnumbered, ruled]{algorithm2e}" b
\begin{algorithm}
	\caption{$1}%
	\label{alg:$2}
	\KwIn{$3}
	\KwOut{$4}
	$0
	\KwRet{$4}
\end{algorithm}
endsnippet
snippet list "\usepackage[langlinenos]{minted}\setminted{linenos, mathescape, autogobble, breaklines, breakanywhere, frame=single}" b
\begin{listing}
	\inputminted[label=$2.py]{${1:python}}{listings/$2.py}
	\caption{$3}%
	\label{lst:$2}
\end{listing}
endsnippet

snippet al "\usepackage{mathtools}" b
\begin{align}
	\label{eq:$1}
	$0
\end{align}
endsnippet
snippet subn "\usepackage{cases}" b
\begin{subnumcases}{$1}%
	\label{eq:$2}
	$0
\end{subnumcases}
endsnippet

snippet bash "\usepackage{bashful}" b
\bash[script, stdout, stderr$1]
$0
\END
endsnippet
snippet py "\usepackage{pythontex}" b
\begin{pyconsole}
$0
\end{pyconsole}
endsnippet

global !p
texMathZones = [
    "texMathZone" + x for x in [
        "A", "AS", "B", "BS", "C", "CS", "D", "DS", "E", "ES", "F", "FS", "G",
        "GS", "H", "HS", "I", "IS", "J", "JS", "K", "KS", "L", "LS", "DS", "V",
        "W", "X", "Y", "Z"
    ]
]
texIgnoreMathZones = ["texMathText"]
texMathZoneIds = vim.eval("map(" + str(texMathZones) + ", 'hlID(v:val)')")
texIgnoreMathZoneIds = vim.eval("map(" + str(texIgnoreMathZones) + ", 'hlID(v:val)')")
ignore = texIgnoreMathZoneIds[0]
def math():
    synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
    try:
        first = next(
            i for i in reversed(synstackids)
            if i in texIgnoreMathZoneIds or i in texMathZoneIds
        )
        return first != ignore
    except StopIteration:
        return False
endglobal

context "math()"
snippet sym "pip install sympy" w
sympy $1 endsympy
endsnippet
context "math()"
snippet 'sympy(.*)endsympy' "\usepackage{txfonts}" wr
`!p
import sympy
exec(sympy.interactive.session.preexec_source)
snip.rv = latex(eval(match.group(1)))
`
endsnippet

context "math()"
snippet lim "\usepackage{txfonts}" i
\lim_{${1:n} \to ${2:\infty}} $0
endsnippet
context "math()"
snippet int "\usepackage{txfonts}" i
\int_{${1:-\infty}}^${2:\infty} $0
endsnippet
context "math()"
snippet sum "\usepackage{txfonts}" i
\sum_{${1:i} = ${2:-\infty}}^${3:\infty} $0
endsnippet
context "math()"
snippet pro "\usepackage{txfonts}" i
\prod_{${1:i} = ${2:-\infty}}^${3:\infty} $0
endsnippet
context "math()"
snippet "([A-Za-z'])(\d)" "myUltiSnips" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet
context "math()"
snippet "([A-Za-z'])_(\d\d)" "myUltiSnips" wrA
`!p snip.rv = match.group(1)`_{`!p snip.rv = match.group(2)`}
endsnippet
context "math()"
snippet "([A-Za-z'])_" "myUltiSnips" wr
`!p snip.rv = match.group(1)`_{${1:${VISUAL}}}
endsnippet
context "math()"
snippet ^ "myUltiSnips" w
^{${1:${VISUAL}}}
endsnippet
context "math()"
snippet '([A-Za-z])\^(\d\d)' "myUltiSnips" wrA
`!p snip.rv = match.group(1)`^{`!p snip.rv = match.group(2)`}
endsnippet

snippet ali "myUltiSnips" i
\begin{aligned}
$0
\end{aligned}
endsnippet
snippet cases "myUltiSnips" i
\begin{cases}
$0
\end{cases}
endsnippet
snippet matrix "myUltiSnips" i
\begin{matrix}
$0
\end{matrix}
endsnippet
snippet bmat "myUltiSnips" i
\begin{bmatrix}
$0
\end{bmatrix}
endsnippet
snippet Bmat "myUltiSnips" i
\begin{Bmatrix}
$0
\end{Bmatrix}
endsnippet
snippet pmat "myUltiSnips" i
\begin{pmatrix}
$0
\end{pmatrix}
endsnippet
snippet vmat "myUltiSnips" i
\begin{vmatrix}
$0
\end{vmatrix}
endsnippet
snippet Vmat "myUltiSnips" i
\begin{Vmatrix}
$0
\end{Vmatrix}
endsnippet
